<template>
	<div>
		<div class="tabctitem">
			<div class="m-hmsrch">
				<form class="m-input f-bd f-bd-btm" method="get" action="#">
					<div class="inputcover"><i class="u-svg u-svg-srch"></i>
						<input type="search" 
							   name="search" 
							   class="input" 
							   autocomplete="off" 
							   placeholder="搜索歌曲、歌手、专辑"
							   @input="keyup()"
							   @keydown.13.preventDefault="prevents()"
							   ref="ChanGe"
						>
					</div>
				</form>
				<div class="m-default">
					<section class="m-hotlist">
						<h3 class="title">热门搜索</h3>
						<ul class="list">
							<li class="item f-bd f-bd-full" v-for="item in list">
								<a class="link" href="javascript:void(0);">{{item.first}}</a>
							</li>
						</ul>
					</section>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import api from '.././api/index.js'
	export default {
		mounted() {
			// 做AJAX请求
			this._initData()
		},
		data() {
			return {
				list: [],
				List:[]
			}
		},
		methods: {
			_initData() {
				return new Promise((resolve, reject) => {
					var xhr = new XMLHttpRequest();
					xhr.open("GET", api.search);
					xhr.send();
					xhr.addEventListener("readystatechange", function() {
						if(xhr.readyState == 4) {
							if(xhr.status == 200) {
								resolve(xhr.response);
							}
						}
					})
				}).then((res) => {
					this.list = JSON.parse(res).result.hots
				})
			},
			keyup(){
				return new Promise((resolve, reject) => {
					var xhr = new XMLHttpRequest();
					xhr.open("GET", api.Search + "?keywords=" + this.$refs.ChanGe.value);
					xhr.send();
					xhr.addEventListener("readystatechange", function() {
						if(xhr.readyState == 4) {
							if(xhr.status == 200) {
								resolve(xhr.response);
							}
						}
					})
				}).then((res) => {
					console.log(res)
					this.List = JSON.parse(res).result.songs
				})
			},
			prevents(){
				console.log(111)
			}
		}
	}
</script>

<style scoped>
	.m-tabct .tabctitem {
		width: 100%;
		height: 100%;
	}
	
	.m-hmsrch {
		background: #fbfcfd;
	}
	
	.f-bd {
		position: relative;
	}
	
	.m-input {
		padding: 15px 10px;
	}
	
	.m-input .inputcover {
		position: relative;
		width: 100%;
		height: 30px;
		padding: 0 30px;
		box-sizing: border-box;
		background: #ebecec;
		border-radius: 30px;
	}
	
	.u-svg-srch {
		width: 13px;
		height: 13px;
		background-image: url(../../public/img/search.svg);
	}
	
	.m-input .u-svg-srch {
		position: absolute;
		left: 0;
		top: 9px;
		margin: 0 8px;
		vertical-align: middle;
	}
	
	.input {
		outline: none;
	}
	
	.m-input .input {
		width: 100%;
		height: 30px;
		line-height: 18px;
		background: transparent;
		font-size: 14px;
		color: #333;
	}
	
	label,
	summary {
		cursor: default;
	}
	
	.m-input .holder {
		position: absolute;
		left: 30px;
		top: 5px;
		font-size: 14px;
		color: #c9c9c9;
		background: transparent;
		pointer-events: none;
	}
	
	address,
	article,
	aside,
	details,
	figcaption,
	figure,
	footer,
	header,
	hgroup,
	menu,
	nav,
	section {
		display: block;
	}
	
	.m-hotlist {
		padding: 15px 10px 0;
	}
	
	.m-hotlist .title {
		font-size: 12px;
		line-height: 12px;
		color: #666;
	}
	
	.m-hotlist .list {
		margin: 10px 0 7px;
	}
	
	input {
		border-radius: 0;
		border: 0;
		background-color: transparent;
	}
	
	a {
		color: #333;
		text-decoration: none;
	}
	
	li {
		list-style: none;
	}
	
	.f-bd {
		position: relative;
	}
	
	.m-hotlist .item {
		display: inline-block;
		height: 32px;
		margin-right: 8px;
		margin-bottom: 8px;
		padding: 0 14px;
		font-size: 14px;
		line-height: 32px;
		color: #333;
	}
	
	.m-input:after {
		border-color: rgba(0, 0, 0, .1);
	}
	
	.m-input:after {
		border-color: rgba(0, 0, 0, .1);
	}
	
	.f-bd:after {
		position: absolute;
		z-index: 2;
		content: "";
		top: 0;
		left: 0;
		pointer-events: none;
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		-webkit-transform-origin: top left;
		transform-origin: top left;
		border: 0 solid rgba(0, 0, 0, .1);
	}
	
	.f-bd-btm:after {
		border-bottom-width: 1px;
	}
	
	.f-bd-full:after {
		border-width: 1px;
	}
	
	.m-hotlist .item:after {
		border-color: #d3d4da;
		border-radius: 32px;
	}
</style>